package com.hex.liyue.commonmodule.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.hex.liyue.R;


/**
 * Created by yukuo on 2016/4/8.
 * 这是一个自定义的ios双选对话框
 */
public class IosChoiceDialog extends Dialog {
    private OnButtonClickListener onButtonClickListener;

    public interface OnButtonClickListener {
        void onOkClickListener();

        void onCancelClickListener();
    }

    public IosChoiceDialog(Context context, String title, String message) {
        this(context, R.style.IOSDialog, title, message);
    }

    public IosChoiceDialog(Context context, int themeResId, String title, String message) {
        super(context, themeResId);
        View view = View.inflate(context, R.layout.dialog_ioschoice, null);
        TextView titleText = (TextView) view.findViewById(R.id.tv_ios_choice_dialog_title);
        titleText.setText(title);
        TextView titleDesc = (TextView) view.findViewById(R.id.tv_ios_choice_dialog_message);
        titleDesc.setText(message);
        TextView titleOk = (TextView) view.findViewById(R.id.tv_ios_choice_dialog_ok);
        titleOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onButtonClickListener) {
                    onButtonClickListener.onOkClickListener();
                }
                dismiss();
            }
        });
        TextView titleCancel = (TextView) view.findViewById(R.id.tv_ios_choice_dialog_cancel);
        titleCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onButtonClickListener) {
                    onButtonClickListener.onCancelClickListener();
                }
                dismiss();
            }
        });
        this.setContentView(view);
        //设置窗口居中
        this.getWindow().getAttributes().gravity = Gravity.CENTER;
    }

    /**
     * 设置按钮的点击事件
     *
     * @param onButtonClickListener
     */
    public void setOnButtonClickListener(OnButtonClickListener onButtonClickListener) {
        this.onButtonClickListener = onButtonClickListener;
    }
}
